package acm;

import java.util.Scanner;

public class 删除数组零元素 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int number=in.nextInt();
        int count=0,n=0,m=0;
        int[] a = new int[number];
        for (int i=0;i<number;i++){
            a[i]=in.nextInt();
            if (a[i]==0){
                count++;
            }
            else {
                a[n]=a[i];
                n++;
            }
        }
        if (count==number){
            System.out.print("0");
        }
        else {
            System.out.print(n);
            System.out.println();
            for (int i=0;i<n;i++){
                if (m==0){
                    System.out.print(a[i]);
                    m++;
                }
                else {
                    System.out.print(" "+a[i]);
                }
            }
        }



    }
}
